package top.whysu.rongcloud.controller;

import io.rong.RongCloud;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.whysu.rongcloud.constant.ConfigConstant;
import top.whysu.rongcloud.dto.http.Response;
import top.whysu.rongcloud.dto.rongcloud.friendship.DisplayNameAccountDTO;
import top.whysu.rongcloud.dto.rongcloud.friendship.FriendShipAccountDTO;
import top.whysu.rongcloud.dto.rongcloud.friendship.FriendShipAllDTO;
import top.whysu.rongcloud.dto.rongcloud.friendship.FriendShipInviteDTO;
import top.whysu.rongcloud.service.RongCloudFriendShipService;
import top.whysu.rongcloud.service.RongCloudUserService;
import top.whysu.rongcloud.util.ResponseUtil;

import javax.annotation.Resource;

/**
 * 好友关系
 */
@RestController
@RequestMapping("/rongCloud/friendship")
public class FriendShipController {
    private RongCloud rongCloud = RongCloud.getInstance(ConfigConstant.appKey, ConfigConstant.appSecret);

    @Resource
    RongCloudUserService rongCloudUserService;
    @Resource
    RongCloudFriendShipService rongCloudFriendShipService;

    /**
     * 发起添加好友请求
     */
    @PostMapping("/invite")
    public Response invite(@RequestBody @Validated FriendShipInviteDTO requestDTO) {
        return rongCloudFriendShipService.wholeInvite(requestDTO);
    }

    /**
     * 同意好友请求
     */
    @PostMapping("/agree")
    public Response agree(@RequestBody @Validated FriendShipAccountDTO requestDTO) {
        return rongCloudFriendShipService.wholeAgree(requestDTO);
    }

    /**
     * 忽略好友请求
     */
    @PostMapping("/ignore")
    public Response ignore(@RequestBody @Validated FriendShipAccountDTO requestDTO) {
        rongCloudFriendShipService.wholeIgnore(requestDTO);
        return ResponseUtil.getSuccessResponse();
    }

    /**
     * 逻辑删除（修改status为30）
     */
    @PostMapping("/delete")
    public Response delete(@RequestBody @Validated FriendShipAccountDTO requestDTO) {
        rongCloudFriendShipService.delete(requestDTO);
        return ResponseUtil.getSuccessResponse();
    }

    /**
     * 修改备注名
     */
    @PostMapping("/set_display_name")
    public Response setDisplayName(@RequestBody @Validated DisplayNameAccountDTO requestDTO) {
        rongCloudFriendShipService.wholeSetDisplayTime(requestDTO);
        return ResponseUtil.getSuccessResponse();
    }

    /**
     * 获取好友列表
     */
    @PostMapping("/all")
    public Response all(@RequestBody @Validated FriendShipAllDTO requestDTO) {
        return ResponseUtil.getSuccessResponse(rongCloudFriendShipService.getAllFriendShipList(requestDTO, false));
    }

    /**
     * 获取单个好友信息
     */
    @PostMapping("/profile")
    public Response profile(@RequestBody @Validated FriendShipAccountDTO requestDTO) {
        return ResponseUtil.getSuccessResponse(rongCloudFriendShipService.getFriendInfo(requestDTO));
    }

    /**
     * "新的朋友"列表
     */
    @GetMapping("/newFriendList")
    public Response newFriendList(@RequestBody @Validated FriendShipAllDTO requestDTO) {
        return ResponseUtil.getSuccessResponse(rongCloudFriendShipService.getAllFriendShipList(requestDTO, true));
    }

}
